<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$ui = new UI();
if ($curruser['acl'] != 5 || $curruser['acl'] == 5 && $curruser['prev_id'] != 0)
{
    diemsg("你不是大股东！");
}
if ($curruser['acl'] != 255)
{
    $userlist = GetUserList($curruser['id']);
    if ($userlist == "")
    {
        $ui->showErrorPage("<p>还没有建立会员！</p>");
        exit();
    }
}
$conf = new Config();
$tpl = new Template2();
include( "member/news.php" );
$rs = getdb("select id,open,round from lotto where open>='" . date("Y-m-d") . "' order by open");
if ($rs->eof)
{
    $ui->showErrorPage("<p>目前没有期数！</p>");
    exit();
}
$lotto_id = $rs->f['id'];
$round = $rs->f['round'];
$open = $rs->f['open'];
$rs->close();
$waitbet = $conf->get("linebet");
$waitbet2 = $conf->get("linebet");
$t2 = strtotime($open . " " . $waitbet);
$stopbet = $conf->get("linebet");
$stopbet2 = $conf->get("linebet");
$t1 = strtotime($open . " " . $stopbet);
$dt = date("Y-m-d");
$tpl->Set("timestap", $t1 - systime());
$tpl->set("phptime", systime());
$tpl->set("open", $open);
$tpl->set("round", d3($round));
$tpl->set("dt", $dt);
$tpl->set("lotto_id", $lotto_id);
$disk = 0;
$split = 1;
include_once( "class_6h/class.menu.php" );
$fieldArr = array("open" => $open, "lotto_id" => $lotto_id, "split_id" => 1);
$onlineMenu = new menu_6h(11, $fieldArr);
$selectid = getvar("select") == "" ? 0 : getvar("select");
$menuList = $onlineMenu->getMenu($selectid);
$tpl->set("menuList", $menuList);
unset($onlineMenu);
$rs = getdb("select * from rate8s where lotto_id=" . $lotto_id . " and user_id=" . $curruser['id']);
if ($rs->eof)
{
    getdb("insert IGNORE into rate8s (lotto_id, user_id) values (" . $lotto_id . ", " . $curruser['id'] . ")");
}
$rs->close();
$percent = 0;
$lostwin = array();
$betcount = array();
$totalamount = array();
$list = array();
$betids = array(7, 8, 9, 10, 11);
foreach ($betids as $bettype)
{
    $totalamount[$bettype] = 0;
    $betcount[$bettype] = 0;
    $list[$bettype] = "";
    $betTypeStr = "";
    switch ($bettype)
    {
        case 9 :
            $betTypeStr = "bettype IN ( 9,33)";
            break;
        case 10 :
            $betTypeStr = "bettype IN (10,32)";
            break;
        default :
            $betTypeStr = "bettype=" . $bettype;
            break;
    }
    $sql = " sum(totalAmt) as totalAmt FROM (\r\n  Select line_nums,(unitmoney*upercent/100) as totalAmt\r\n  from bet where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  UNION ALL\r\n  Select line_nums,(unitmoney*percent255/100) as totalAmt\r\n  from bet2 where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  UNION ALL\r\n  Select line_nums,(amount*-1) as totalAmt\r\n  from bet8 where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  ) A";
    $rs1 = getdb("SELECT " . $sql);
    $rs2 = getdb("Select line_nums," . $sql . " GROUP BY line_nums Order by totalAmt desc LIMIT 20");
    $totalamount[$bettype] = round($rs1->f[0], 0);
    while ($totalamount[$bettype] != 0 && $rs2->eof)
    {
        $c = $rs2->f[0];
        $n = round($rs2->f[1], 0);
        if ($c != "" && $n != 0)
        {
            $list .= $bettype;
            $list .= $bettype;
            $list .= $bettype;
        }
        $rs2->movenext();
    }
}
$rs1->close();
$rs2->close();
$tpl->set("money08", $totalamount[8]);
$tpl->set("money09", $totalamount[9]);
$tpl->set("money07", $totalamount[7]);
$tpl->set("money10", $totalamount[10]);
$tpl->set("money11", $totalamount[11]);
$tpl->set("list8", $list[8]);
$tpl->set("list9", $list[9]);
$tpl->set("list7", $list[7]);
$tpl->set("list10", $list[10]);
$tpl->set("list11", $list[11]);
$rs8 = getdb("select * from rate8 where lotto_id={$lotto_id} and disk=1");
if ($rs8->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中(三全中无赔率)，请稍後！</p>");
    exit();
}
$rate8Arr = array();
$i = 1;
while ($i < 50)
{
    $rate8Arr["r8_{$i}"] = intval($rs8->f["r" . d2($i)]);
    ++$i;
}
sort($rate8Arr);
$rs8->close();
$tpl->set("r8_hi", $rate8Arr[48]);
$tpl->set("r8_lo", $rate8Arr[0]);
$rs = getdb("select * from rate5a where lotto_id=" . $lotto_id);
if ($rs->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$tpl->set("r9_1", $rs->f['r9_1']);
$tpl->set("r9_2", $rs->f['r9_2']);
$tpl->set("r33_1", $rs->f['r33_1']);
$tpl->set("r33_2", $rs->f['r33_2']);
$tpl->set("r7_1", $rs->f['r7_1']);
$tpl->set("r10_1", $rs->f['r10_1']);
$tpl->set("r10_2", $rs->f['r10_2']);
$tpl->set("r32_1", $rs->f['r32_1']);
$tpl->set("r32_2", $rs->f['r32_2']);
$tpl->set("r11_1", $rs->f['r11_1']);
$tpl->load("main", "snow5.htm");
$tpl->show("main");
$ui->footer();
?>